﻿using DevExpress.XtraCharts;
using Lamex.Interface;
using Lamex.Library;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Lamex.mMachine.UI
{
    public partial class frmMAC_Equipment_Detail_Depre : frmBaseChild
    {
        DataTable dataTable = new DataTable();
        DataTable dataTable2 = new DataTable();
        string colums_xaxis;
        string colums_yaxis;
        string colums_yaxis2;
        int flag;
        public frmMAC_Equipment_Detail_Depre()
        {
            InitializeComponent();
        }
        public frmMAC_Equipment_Detail_Depre(DataTable dt,DataTable dt2, string xaxis, string yaxis, string yaxis2, int flag_chart)
        {
            InitializeComponent();
            dataTable = dt;
            dataTable2 = dt2;
            colums_xaxis = xaxis;
            colums_yaxis = yaxis;
            colums_yaxis2 = yaxis2;
            flag = flag_chart;
        }
        private void frmMAC_Equipment_Detail_Depre_Load(object sender, EventArgs e)
        {
            try { base.InitButtons(); } catch { }//初始化标准功能，因要应用于RibbonForm，所以加入异常处理
            sbtnRefresh_Click(null, null);
        }
        private void sbtnRefresh_Click(object sender, EventArgs e)
        {
            //显示表格
            ShowGridInfo(dataTable, dataTable2);
            //显示图表           
            Common.ChartControlHelper.setData_Chart(chartControl1, ViewType.Pie, dataTable, colums_xaxis, colums_yaxis);
        }
        private void ShowGridInfo(DataTable dt,DataTable dt2)
        {
            if (dt.Rows.Count > 0 && dt != null)
            {
                DataTable dtNew = dt.DefaultView.ToTable(false, new string[] { dt.Columns[0].ColumnName, dt.Columns[1].ColumnName, dt.Columns[3].ColumnName });
                gridControl1.DataSource = dtNew;
                gridView1.OptionsBehavior.Editable = false;
                gridView1.OptionsView.ColumnAutoWidth = true;
                gridView1.Appearance.HeaderPanel.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;

                //设置页脚汇总
                gridView1.OptionsView.ShowFooter = true;
                gridView1.Columns[0].SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Count;
                gridView1.Columns[0].SummaryItem.DisplayFormat = "合计：";

                gridView1.Columns[1].SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Sum;
                gridView1.Columns[1].SummaryItem.DisplayFormat = "{0:N0}";
            }
            if (dt2.Rows.Count > 0 && dt2 != null)
            {
                gridControl2.DataSource = dt2;
                gridView2.Appearance.HeaderPanel.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
            }
        }
        public override void DoView(IButtonInfo sender)
        {
            sbtnRefresh_Click(null, null);
            base.DoView(sender);
        }
        public override void DoExport(IButtonInfo sender)
        {
            Common.ExportHelper exportHelper = new Common.ExportHelper();
            exportHelper.ExportToExcel(gridControl1,gridControl2, chartControl1);
            base.DoExport(sender);
        }
        public override void DoPrint(IButtonInfo sender)
        {
            Common.ExportHelper exportHelper = new Common.ExportHelper();
            exportHelper.PrintPreview(gridControl1, gridControl2, chartControl1);
            base.DoPrint(sender);
        }
        private void gridView1_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
        {
            if (e.Info.IsRowIndicator && e.RowHandle >= 0)
            {
                e.Info.DisplayText = (e.RowHandle + 1).ToString();
            }
        }

        private void gridView2_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
        {
            if (e.Info.IsRowIndicator && e.RowHandle >= 0)
            {
                e.Info.DisplayText = (e.RowHandle + 1).ToString();
            }
        }

        private void frmMAC_Equipment_Detail_Depre_Resize(object sender, EventArgs e)
        {
            this.splitContainerControl1.SplitterPosition = splitContainerControl1.Width / 2;
        }
    }
}
